
//
// async http request
//
@interface AsyncHttpRequest : NSObject

//
// callback
//
typedef void (^AsyncHttpRequestFinishCallback)(AsyncHttpRequest*);

//
// protocol
//
@property(strong, nonatomic, readwrite) NSString*							protocol;

//
// domain
//
@property(strong, nonatomic, readwrite) NSString*							domain;

//
// port
//
@property(assign, nonatomic, readwrite) NSInteger							port;

//
// rel path
//
@property(strong, nonatomic, readwrite) NSString*							relPath;

//
// auth user name
//
@property(strong, nonatomic, readwrite) NSString*							authUserName;

//
// auth password
//
@property(strong, nonatomic, readwrite) NSString*							authPassword;

//
// request
//
@property(strong, nonatomic, readwrite) NSMutableURLRequest*				request;

//
// post data
//
@property(strong, nonatomic, readwrite) NSData*								postData;

//
// connection
//
@property(strong, nonatomic, readwrite) NSURLConnection*					connection;

//
// response
//
@property(strong, nonatomic, readwrite) NSHTTPURLResponse*					response;

//
// error
//
@property(strong, nonatomic, readwrite) NSError*							error;

//
// data buffer
//
@property(strong, nonatomic, readwrite) NSMutableData*						dataBuffer;

//
// auto redirect
//
@property(assign, nonatomic, readwrite) BOOL								autoRedirect;

//
// callback
//
@property(copy, nonatomic, readwrite) AsyncHttpRequestFinishCallback		callback;

//
// setup request
//
- (void)setupRequest;

//
// start
//
- (void)startWithCallback:(AsyncHttpRequestFinishCallback)callback;

//
// redirect
//
- (NSURLRequest*)connection:(NSURLConnection*)connection willSendRequest:(NSURLRequest*)request redirectResponse:(NSURLResponse*)response;

//
// failed
//
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error;

//
// received response
//
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response;

//
// received data
//
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data;

//
// finished
//
- (void)connectionDidFinishLoading:(NSURLConnection*)connection;

//
// error description
//
- (NSString*)errorDescription;

//
// setup cookie
//
- (NSHTTPCookie*)cookieWithName:(NSString*)cookieName value:(NSString*)value expires:(NSDate*)expires;

//
// set error message
//
- (void)setErrorMessage:(NSString*)message code:(NSInteger)code domain:(NSString*)domain;

@end
